﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __IMPL_MGR_H__
#define __IMPL_MGR_H__

namespace xos_encrypt
{

    class mgr : public i_encrypt_mgr
    {
    public:
        typedef xos::release_impl< mgr > T;

    public:
        static int static_init( xos_container::i_container * pContainer, i_encrypt_mgr ** ppv );
        static xos_container::i_container * container();
        static xos_common::i_common * common();
        static xos_log::i_log * log();
        static xos_box::i_big_buf * big_buf();
        static xos_box::i_buf * buf();
        static xos::i_misc * misc();
        static xos::i_crt * crt();
        static xos::i_xos * xos();
        static mgr * get();

    protected:

        // 
        // rsa参数
        // 
        std::string m_private_key_file;
        std::string m_public_key_file;
        // 
        // ssl参数
        // 
        std::string m_server_cert;
        std::string m_server_key;
        std::string m_client_cert;
        std::string m_client_key;

    public:
        // 
        // rsa参数
        // 
        void * m_pPrivateRSA;
        void * m_pPublicRSA;
        int m_nRsaLen;

        // 
        // ssl参数
        // 
        void * m_pClientCtx;
        void * m_pServerCtx;

    public:
        mgr();
        ~mgr();

    public:
        // 初始化及创建对象
        int create( enumInterfaceType eType, void ** ppv );

        // ssl方法
        int set_ssl_server_cert( const char * lpszFile );
        int set_ssl_server_key( const char * lpszFile );
        int set_ssl_client_cert( const char * lpszFile );
        int set_ssl_client_key( const char * lpszFile );
        int init_ssl();

        // rsa方法
        int set_rsa_private_key( const char * lpszFile );
        int set_rsa_public_key( const char * lpszFile );
        int init_rsa();

    protected:
        int put_back_to_pool( T * pT, bool bLock );

        int init_ssl_server();
        int init_ssl_client();

        int term_ssl();
        int term_rsa();

        int init_data();
        int init();
        int term();

    };

} // xos_encrypt

#endif // __IMPL_MGR_H__
